import java.util.Scanner;


//find unique and duplicate words in the string

//										Please enter the input line
//										this this hello is hello me this
//										Input string is "this this hello is hello me this"
//										
//										Occurrence count of duplicate words 
//										"hello" - duplicated 2 times in the array 
//										"this" - duplicated 3 times in the array 
//										
//										Unique words in the array are 
//										"is"
//										"me"




public class Assignment7 {

	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		System.out.println("Please enter the input line");
		String mystr = s.nextLine();
		String[] myarray = mystr.split(" "); 
		System.out.format("Input string is \"%s\"", mystr);	
		
		System.out.format("%n%nOccurrence count of duplicate words %n");
		int numOfWords = myarray.length;
		
		String[] uniquearray = new String[numOfWords];
		int uniqueindex = 0;
		
		for(int i=0;i<numOfWords;i++) {
			String currentword = myarray[i];
			int occurrencecount = 0;
			boolean isunique = true;
			for(int j=0;j<numOfWords;j++) {
				if((currentword.equals(myarray[j]))&&(i!=j)) {
					isunique = false;
					if(i<j) //duplicate number occurrence already printed
						occurrencecount = 0;
					else 
						occurrencecount++;
				}
				
			}
			if(isunique) {
				uniquearray[uniqueindex] = myarray[i];
				uniqueindex++;
			}
			if((!isunique)&&(occurrencecount != 0))
				System.out.format("\"%s\" - duplicated %d times in the array %n" , myarray[i], occurrencecount+1);
		}
		System.out.println();
		System.out.print("Unique words in the array are ");
		for(int i=0;i<uniqueindex;i++) {
			System.out.format("%n\"%s\"", uniquearray[i]);			
		}
		System.out.println();
		
		
	}
	
}
